<#include '/admin/header.html' >
<link rel="stylesheet" type="text/css" href="${ctx}/adminthemes/version3/plugins/select2/css/select2.min.css"/>
<script type="text/javascript" src="${ctx}/adminthemes/version3/plugins/select2/js/select2.min.js"></script>
<script type="text/javascript" src="${ctx}/statics/e_tools/js/jquery.goodsCatsEdit.js"></script>
<style>
.__GCD__content .__GCD__input input{
height:30px;
line-height:30px;
padding:4px 10px;
}
</style>
<div class="admin-main" id="__cat_box__" style="margin-top: 30px;">
	
    <script>
        var ctx = '${ctx}';
        var _goodsCatEdit = $('#__cat_box__').goodsCatsEdit({
            canEdit  : true,
            api	: '/shop/admin/region/list-children.do',
            maxLeave : 4,
            addCat   : function (cat) {            
            	if(cat.parent_data==null){
            		var url = "${ctx}/shop/admin/region/add.do";
            	}else{
            		var url =  "${ctx}/shop/admin/region/children.do?region_id="+cat.parent_data.data.id;
                }
                layer.open({
                    type: 2,
                    title: '添加地区',
                    area: ['600px', '400px'],                
                    content: url,
                    scrollbar: true,//是否允许浏览器出现滚动条
                    maxmin :true,//右上角可否放大缩小                
                })  
            },
            editCat  : function (cat) {            
            	 layer.open({
                     type: 2,
                     title: '修改地区',
                     area: ['600px', '400px'],
                     content: "${ctx}/shop/admin/region/edit.do?region_id=" + cat.id,
                     scrollbar: true,//是否允许浏览器出现滚动条
                     maxmin :true,//右上角可否放大缩小
                 })  
            },
            deleteCat: function (cat) {
            	layer.confirm('确定要删除这个地区吗？', {icon: 3, title:'提示'}, function (index) {
                    layer.close(index);
                    var __load = layer.load(2);
                    $.ajax({
                        url: "${ctx}/shop/admin/region/delete.do?ajax=yes",                        
                        data: { region_id: cat.id },
                        type: 'POST',
                        success: function (res) {
                            layer.close(__load);
                            if(res.result === 1){
                                layer.msg('删除成功！', { icon: 1 });
                                _goodsCatEdit.refreshData();
                            }else {
                                layer.msg(res.message, { icon: 5 });
                            }
                        },
                        error: function () {
                            layer.close(__load);
                            layer.msg('出现错误，请稍候再试！', { icon: 2 });
                        }
                    })
                })
            },
            callback: function (cat) {
                console.log(cat)
            }
        }).init();
        
        function init() {
    		if (!confirm("确认要将地区初始化吗，此操作会清除当前地区数据？")) {
    			return false;
    		}
    		$("#initRegion").attr("disabled","disabled");
    		$.Loading.show("正在初始化地区数据......");
    		$.ajax({
    			url : "${ctx}/shop/admin/region/reset.do?ajax=yes",
    			dataType : "json",
    			success : function(res) {
    				$.Loading.success(res.message);
    				location.reload();
    			},
    			error : function() {
    				alert("初始化所需时间较长,请三分钟之后再来查看");
    				$("#initRegion").removeAttr("disabled");
    				$.Loading.hide();
    			}
    			
    		});
    	}
    </script>
    <div style="text-align:center;padding-bottom: 10px;"> 
		<button href="javascript:void(0)" class="layui-layer-btn0 layui-btn layui-btn-normal" onclick="init()" id="initRegion">初始化</button>
	</div>
</div>

<#include '/admin/footer.html' >
